//version:1.0.0
window.save = function () {
    let data = window.vueInstance.$children[0].$children[0].$children[0].$children[1].$children[1].$children[0];
    if (!data.$route.query.ticket && !data.$route.query.projid) return;
    data.formValidate(['form']);
    data.customBackFun();
};
export default {
    data() {
        return {
            form:{
                aae160: {
                    key: '',
                    value: '',
                    p: 'R'
                },
                aae035: {
                    value: '',
                    p: 'R'
                },
                aae013: {
                    value: '',
                    p: 'E'
                },

            },
            tableData: {},

            rules:{
                aae160: [
                     {required: true, validator: this.$rules.test_noBlank, trigger: 'change'}

                ],
                aae035: [
                     {required: true, validator: this.$localRules.DateCheck, trigger: 'blur'}

                ],

            },
            codeTypes:{
                AAE160:[],
                AAE140:[],
                AAZ289:[],
                AAB033:[],

            },
            codeTypeFilters:{
                AAE160:" (aaa105='05')",

            },
            pager: {
                page: 1,
                size: 10
            },
            total: 0,
        }
    },
    computed: {
        refresh() {
            return localStorage.getItem('refresh') || false;
        },
        functionId() {
            if (this.$store.getters.init.path !== this.$route.path) return;
            if (this.$store.getters.init.mdParam === null || this.$store.getters.init.mdParam === undefined) return;
            if (this.$store.getters.init.mdParam.functionid === undefined) return;
            return this.$store.getters.init.mdParam.functionid;
        },
        backFun() {
            return this.$store.getters.backFun;
        },
        init_formData() {
            if (this.$store.getters.init.path !== this.$route.path)  return;
            return this.$store.getters.init.form;
        },
        doInitformData: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.formData;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },
        init_panel() {
            if (this.$store.getters.init.path !== this.$route.path)  return;
            return this.$store.getters.init.panel;
        },
        doInitpanel: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.panel;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },
        init_tableData() {
            return this.$store.getters.init.tableData;
        },
        doInittableData: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.tableData;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },

    },
    created() {
        let param = {
            path: this.$route.path,
            codeTypes:this.codeTypes,
            codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
            form:this.form,
            tableData:this.tableData

        };
        if (this.refresh === 'true') {
            this.$store.dispatch('SET_INIT', param);
            sessionStorage.removeItem(this.$route.path);
        }
        if (this.$route.query.keepAlive === undefined) {
            this.$store.dispatch('SET_INIT', param);
        }
    },
    watch: {
        refresh: {
            handler(value) {
                return value;
            },
        deep: true
        },
        init_formData: {
            handler(value) {
                if (value == undefined) return;
                this.getformData(value);
            },
            deep: true
        },
        doInitformData: {
            handler(value) {
                if (value == undefined) return;
                this.$refs.form.clearValidate();

                this.getformData(value);
            },
            deep: true
        },
        doInittableData: {
            handler(value) {
                if (value == undefined) return;
                this.gettableData(value);
            },
            deep: true
        },
        init_panel: {
            handler(value) {
                if (value == undefined) return;
                this.getpanel(value);
            },
            deep: true
        },
        doInitpanel: {
            handler(value) {
                if (value == undefined) return;
                
                this.getpanel(value);
            },
            deep: true
        },

        backFun: {
            handler(value) {
                if (value === null) return;
                this.customBackFun();
                let backFun = [];
                backFun = value.split(',');
                if (backFun.indexOf('rDoInit') >= 0) {
            let codeTypes = {
                AAE160:[],
                AAE140:[],
                AAZ289:[],
                AAB033:[],

            };
            let form = {
                aae160: {
                    key: '',
                    value: '',
                    p: 'R'
                },
                aae035: {
                    value: '',
                    p: 'R'
                },
                aae013: {
                    value: '',
                    p: 'E'
                },

            };
            let tableData= {};

        let param = {
            path: this.$route.path,
            codeTypes:codeTypes,
            codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
            form:form,
            tableData:tableData

        };
                    this.$store.dispatch('SET_INIT', param);
                }
            }
        }
    },
    mounted() {
        if (this.$store.getters.cacheData === null) return;
        if (this.$store.getters.cacheData[this.$route.path] === undefined)  return;
        if (this.$store.getters.cacheData[this.$route.path].path !== this.$route.path) return;
        if (this.$store.getters.cacheData[this.$route.path].form !== undefined) {
            this.getformData(this.$store.getters.cacheData[this.$route.path].form);
        }
        if (this.$store.getters.cacheData[this.$route.path].tableData !== undefined) {
            this.gettableData(this.$store.getters.cacheData[this.$route.path].tableData);
        }
        if (this.$store.getters.cacheData[this.$route.path].panel !== undefined) {
            this.getpanel(this.$store.getters.cacheData[this.$route.path].panel);
        }

    },
    beforeRouteLeave(to, from, next) {
        let param = {
            path: this.$route.path,
            codeTypes: this.$store.getters.codeTypes,
            codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
            form:this.form,
            tableData:this.tableData

        };
        if (from) {
            this.$store.dispatch('SET_CACHEDATA', param);
        }
        next();
    },
    methods: {
        getformData(value) {
            this.form = value;
        },
        gettableData(value) {
            this.tableData = value;
        },
        getpanel(value) {
            this.panel = value;
        },


        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
        },
        handleEdit(id) {
            this.dialogFormVisible = true;
        },
        deleteCurrentRow(val){
            this.tableData.Data.splice(this.tableData.Data.findIndex((value,index,ary) => value == val),1);
        },
        formValidate(value){
            if(value && value.length>0){
                let btn = true;
                value.forEach((item,index)=>{
                    if(!btn) return
                    this.$refs[item].validate((valid) => {
                        if (valid) {
                            btn = true;
                        } else {
                            btn = false;
                        }
                    });
                })
                if(btn) this.$refs.save.btn();
            }
        },

        customBackFun(){//自定义方法体
},
    },
}
